package cn.cloudtogo.common.jwt;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Builder;
import lombok.Data;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author yaolianhua789@gmail.com
 **/
@Data
@Builder
public class PayLoadClaims {

    @JsonProperty("iss")
    private String issuer;
    @JsonProperty("sub")
    private String subject;
    @JsonProperty("exp")
    private Date expiresAt;
    @JsonProperty("nbf")
    private Date notBefore;
    @JsonProperty("iat")
    private Date issuedAt;
    @JsonProperty("aud")
    private List<String> audience;
    @JsonProperty("jti")
    private String id;

    private Map<String, String> data;

    public void expiredAfterDays(Integer day) {
        expiredAfterHours(24 * day);
    }

    public void expiredAfterHours(Integer hour) {
        expiredAfterMinutes(60 * hour);
    }

    public void expiredAfterMinutes(Integer minute) {
        expiredAfterSeconds(60 * minute);
    }

    public void expiredAfterSeconds(Integer second) {
        issuedAt = new Date();
        notBefore = new Date();
        expiresAt = new Date(System.currentTimeMillis() + second * 1000);

    }


}
